<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class DelayOrderStepCategoryConfirmTable extends AbstractMigration
{
    public function up()
    {
        $this->table('delay_order_task_step_category_confirm', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '延期单任务环节确认情况'])
            ->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => 'ID'])
            ->addColumn('parent_uuid', 'string', ['default' => '', 'null' => false, 'limit' => 36, 'comment' => '父级uuid'])
            ->addColumn('uuid', 'string', ['default' => '', 'null' => false, 'limit' => 36, 'comment' => '父级uuid'])
            ->addColumn('delay_order_id', 'integer', ['default' => 0, 'null' => false, 'limit' => 11, 'comment' => '延期单ID'])
            ->addColumn('delay_order_task_id', 'integer', ['default' => 0, 'null' => false, 'limit' => 11, 'comment' => '延期单任务ID'])
            ->addColumn('step_category_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '环节ID'])
            ->addColumn('confirm_user_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '确认用户id'])
            ->addColumn('confirm_at', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '确认时间'])
            ->addColumn('is_active', 'enum', ['values' => 'yes,no', 'default' => 'no', 'comment' => '是否当前确认环节'])
            ->addColumn('is_confirmed', 'enum', ['values' => 'yes,no', 'default' => 'no', 'comment' => '是否已确认'])
            ->addColumn('is_pass', 'enum', ['values' => 'yes,no', 'default' => 'no', 'comment' => '确认结果,是否通过'])
            ->addColumn('is_self_step_category', 'enum', ['values' => 'yes,no', 'default' => 'no', 'comment' => '是否本环节'])
            ->addColumn('need_delay', 'enum', ['values' => 'yes,no', 'default' => 'no', 'comment' => '是否需要延期'])
            ->addColumn('delay_to', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '需要延期到的时间'])
            ->addColumn('delay_reason', 'text', ['null' => true, 'comment' => '延期原因'])
            ->addColumn('created', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建时间'])
            ->addColumn('created_by', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建人'])
            ->addColumn('updated', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '更新时间'])
            ->addColumn('updated_by', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '更新人'])
            ->addIndex(['delay_order_task_id', 'step_category_id', 'confirm_user_id'], ['type' => 'unique', 'name' => 'idx_unique_project_step_category_user'])
            ->addIndex(['uuid'], ['type' => 'unique', 'name' => 'idx_unique_uuid'])
            ->addIndex(['confirm_user_id'], ['name' => 'idx_confirm_user_id'])
            ->addIndex(['step_category_id'], ['name' => 'idx_step_category_id'])
            ->addIndex(['delay_order_task_id'], ['name' => 'idx_delay_order_task_id'])
            ->addIndex(['delay_order_id'], ['name' => 'idx_delay_order_id'])
            ->save();
    }

    public function down()
    {
        $this->table('delay_order_task_step_category_confirm')
            ->drop()
            ->save();
    }
}
